<template>
	<div class='content-box'>
		<div style='padding:50px 0px 50px 200px;'>
			<div style='width:600px;'>
				<el-form :model='formData' :rules='rules' ref='formData' label-width='100px' label-position='left'>
					<el-form-item label='LOGO' prop='logo'>
						<upload v-on:upload='formData.logo=$event' :fileUrl='logoUrl'></upload>
					</el-form-item>
					<el-form-item label='名称' prop='name'>
						<el-input type='text' v-model='formData.name' autocomplete='off'></el-input>
					</el-form-item>
					<el-form-item label='版本号' prop='version'>
						<el-input type='text' v-model='formData.version' autocomplete='off'></el-input>
					</el-form-item>
					<el-form-item label='联系方式' prop='tel'>
						<el-input type='text' v-model='formData.tel' autocomplete='off'></el-input>
					</el-form-item>
					<el-form-item label='企业名称' prop='companyName'>
						<el-input type='text' v-model='formData.companyName' autocomplete='off'></el-input>
					</el-form-item>
					<el-form-item label='关于我们' prop='content'>
						<el-input type='text' v-model='formData.content' autocomplete='off'></el-input>
					</el-form-item>
					<el-form-item label=''>
						<el-button @click='$router.go(-1)'>返回</el-button>
						<el-button @click='submit' class='m-l-20' type='primary'>保存</el-button>
					</el-form-item>
				</el-form>
			</div>
		</div>
	</div>
</template>

<script>
	import { Request, successToast, errorToast } from '@/utils'
	import upload from '@/components/upload.vue'
	
	let request = new Request()
	
	export default {
		data() {
			return {
				logoUrl : '',
				
				formData : {
					logo : '',
					name : '',
					version : '',
					tel : '',
					companyName : '',
					content : ''
				},
				
				rules : {
					logo : {required : true, message : '请上传logo'},
					name : {required : true, message : '请填写名称'},
					version : {required : true, message : '请填写版本号'},
					tel : {required : true, message : '请填写联系方式'},
					companyName : {required : true, message : '请填写公司名称'},
					content : {required : true, message : '请填写关于我们的内容'}
				}
			}
		},
		
		methods : {
			submit : function(){
				this.$refs.formData.validate((valid) => {
					if(!valid) return
					
					
					request.post('home/set/about', res => {
						if(res.code == 0){
							successToast('保存成功', this)
						}else{
							errorToast(res.msg, this)
						}
					}, this.formData)
					
				})
			}
		},
		
		components : {
			upload
		},
		
		created () {
			request.get('home/set/about', res => {
				if(res.code == 0){
					let data = res.data
					for(let k in this.formData){
						this.formData[k] = data[k]
					}
					
					this.logoUrl = this.formData.logo
				}
			})
		}
	}
</script>

<style>

</style>
